package com.jinyu.gateway.controller;

import com.jinyu.gateway.registry.ServerNode;
import com.jinyu.gateway.registry.RegistryCenter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

@RestController
public class TestController {
    @GetMapping("/test")
    public String test() throws InterruptedException {
        Thread thread = new Thread(() -> {
            try {
                TimeUnit.DAYS.sleep(1000);
            } catch (InterruptedException interruptedException) {
                interruptedException.printStackTrace();
            }
        }, "Daemon-T");
        thread.setDaemon(true);
        thread.start();
        TimeUnit.SECONDS.sleep(15);
        return "test";
    }

    @GetMapping("/getAllRegisteredService")
    public Map<String, Set<ServerNode>> getAllRegisteredNode() {
        return RegistryCenter.getAllRegisteredServer();
    }
}
